<template>
  <div class="upload_voucher">
    <div class="payer_info" v-if="resData.gathering_info" v-html="resData.gathering_info"></div>
    <div class="upload_img" v-if="resData.need_proof == 1">
      <p class="title">上传凭证<span>（最多上传3张图）</span></p>
      <SmallUploadImg ref="smallUploadImg" :imageList="fileList" :maxLength="3" @changeImgList="changeImgList"></SmallUploadImg>
    </div>
    <div class="btn_box">
      <div class="btn" @click="handleConfirmUpload">确定提交</div>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'

import SmallUploadImg from '@/components/SmallUploadImg'
import { saveOrderVoucher } from '@/api/order/order.js'
import { dlsSuccess } from '@/api/public/index.js'

export default Vue.extend({
  components: {
    SmallUploadImg
  },
  data() {
    return {
      detailAll: {
        detail: {
          status: 0
        }
      },
      resData: {},
      fileList: [],
      postData: {
        order_id: '',
        image_list: []
      }
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      const data = {}
      if (this.$route.query.id) {
        data.order_id = this.$route.query.id
        this.postData.order_id = this.$route.query.id
      }
      if (this.$route.query.type) {
        data.type = this.$route.query.type
      }
      dlsSuccess(data).then(res => {
        if (res.status == 1) {
          this.resData = res.data
        } else {
          this.$Error(res.msg)
        }
      })
    },
    JumpName(url, data) {
      this.$JumpName(this, url, data)
    },
    // 上传凭证
    changeImgList(val) {
      this.postData.image_list = val
    },
    // 确定上传
    handleConfirmUpload() {
      saveOrderVoucher(this.postData).then(res => {
        if (res.status === 1) {
          this.$Error('操作成功')
          this.JumpName('uploadSuccess')
        } else {
          this.$Error('上传失败, 请重新上传')
        }
      })
    }
  }
})
</script>

<style lang="scss">
@import 'src/styles/mixin';
.upload_voucher{
  font-size: 28px;
  padding: 16px 24px 140px;
  .upload_img{
    padding: 32px 24px 16px;
    background-color: #fff;
    .title{
      font-size: 28px;
      color: #333;
      line-height: 44px;
      margin-bottom: 32px;
      span{
        font-size: 24px;
        line-height: 40px;
      }
    }
  }
  .btn_box{
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    padding: 16px 24px;
    background-color: #fff;
    .btn{
      font-size: 32px;
      color: #fff;
      width: 100%;
      height: 92px;
      line-height: 92px;
      text-align: center;
      border: 1px solid #EC2213;
      background-color: #EC2213;
      border-radius: 46px;
      box-sizing: border-box;
    }
  }
}
</style>

<style lang="scss">
.payer_info{
  text-align: center;
  margin-bottom: 16px;
  padding: 32px 0;
  background-color: #fff;
  p{
    font-size: 28px;
    color: #333;
    line-height: 44px;
    margin-bottom: 8px;
    &:last-child{
      margin-bottom: 0;
    }
    a{
      color: #4381E6;
    }
    img{
      max-width: 100%;
      width: 100%;
      border-radius: 12px;
    }
  }
}
</style>